package zhan.aop.aspectj;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

//@Aspect
//@Component
public class MyCacheableInterceptor {
    private static final Log log = LogFactory.getLog(MyCacheableInterceptor.class);

    @Autowired
    RedisTemplate redisTemplate;

    @Around("execution(* zhan.service.*.select*(..)) || execution(* zhan.service.*.find*(..))")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {

        log.info("------------------>进入环绕方法");
//            joinPoint.getSignature();
//        System.out.println("=================>joinPoint.getSignature()   :"+joinPoint.getSignature());
        String methodName = joinPoint.getSignature().getName();
        //System.out.println("--------------->methodName:"+methodName);
        log.info("=================>joinPoint.getSignature()   :"+joinPoint.getSignature());
            String targetName = joinPoint.getTarget().getClass().getName();
        //System.out.println("=================>name     :"+targetName);
        log.info("=================>name     :"+targetName);
//            String declaringTypeName = joinPoint.getSignature().getDeclaringTypeName();
//        System.out.println("=================>declaringTypeName    :"+declaringTypeName);
//        log.info("=================>declaringTypeName    :"+declaringTypeName);




        Object[] args = joinPoint.getArgs();
        log.info("=================>args     :"+args);

        /** 这里查询完毕后要返回，不然控制层的不到数据*/
        Object o = joinPoint.proceed();
//        ValueOperations operations = redisTemplate.opsForValue();
//        operations.set(methodName,o);
        System.out.println("------------------------>查询完毕的日志");
        log.info("------------------------>查询完毕的日志");
        return o;
    }
}
